package com.ruoyi.jxsx.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jxsx.domain.JxsxTraining;
import com.ruoyi.jxsx.service.IJxsxTrainingService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模拟实训Controller
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@Controller
@RequestMapping("/jxsx/training")
public class JxsxTrainingController extends BaseController
{
    private String prefix = "jxsx/training";

    @Autowired
    private IJxsxTrainingService jxsxTrainingService;

    @RequiresPermissions("jxsx:training:view")
    @GetMapping()
    public String training()
    {
        return prefix + "/training";
    }

    /**
     * 查询模拟实训列表
     */
    @RequiresPermissions("jxsx:training:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JxsxTraining jxsxTraining)
    {
        startPage();
        List<JxsxTraining> list = jxsxTrainingService.selectJxsxTrainingList(jxsxTraining);
        return getDataTable(list);
    }

    /**
     * 导出模拟实训列表
     */
    @RequiresPermissions("jxsx:training:export")
    @Log(title = "模拟实训", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JxsxTraining jxsxTraining)
    {
        List<JxsxTraining> list = jxsxTrainingService.selectJxsxTrainingList(jxsxTraining);
        ExcelUtil<JxsxTraining> util = new ExcelUtil<JxsxTraining>(JxsxTraining.class);
        return util.exportExcel(list, "模拟实训数据");
    }

    /**
     * 新增模拟实训
     */
    @RequiresPermissions("jxsx:training:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存模拟实训
     */
    @RequiresPermissions("jxsx:training:add")
    @Log(title = "模拟实训", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JxsxTraining jxsxTraining)
    {
        return toAjax(jxsxTrainingService.insertJxsxTraining(jxsxTraining));
    }

    /**
     * 修改模拟实训
     */
    @RequiresPermissions("jxsx:training:edit")
    @GetMapping("/edit/{trainingId}")
    public String edit(@PathVariable("trainingId") String trainingId, ModelMap mmap)
    {
        JxsxTraining jxsxTraining = jxsxTrainingService.selectJxsxTrainingByTrainingId(trainingId);
        mmap.put("jxsxTraining", jxsxTraining);
        return prefix + "/edit";
    }

    /**
     * 修改保存模拟实训
     */
    @RequiresPermissions("jxsx:training:edit")
    @Log(title = "模拟实训", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JxsxTraining jxsxTraining)
    {
        return toAjax(jxsxTrainingService.updateJxsxTraining(jxsxTraining));
    }

    /**
     * 删除模拟实训
     */
    @RequiresPermissions("jxsx:training:remove")
    @Log(title = "模拟实训", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jxsxTrainingService.deleteJxsxTrainingByTrainingIds(ids));
    }
}
